﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class modify_table_stdtable_Exp : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainStdTableColumnConfig");

            migrationBuilder.DropColumn(
                name: "StdTableCode",
                table: "MainStdTableDict");

            migrationBuilder.RenameColumn(
                name: "Descr",
                table: "MainStdTableDict",
                newName: "Exp");

            migrationBuilder.AddColumn<int>(
                name: "TableTemplateType",
                table: "MainStdTableDict",
                type: "integer",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "MainStdTableColumnDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    StdTableDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    HeaderName = table.Column<string>(type: "text", nullable: false),
                    Field = table.Column<string>(type: "text", nullable: false),
                    Type = table.Column<string>(type: "text", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    ColumnWidthType = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdTableColumnDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdTableColumnDict_MainStdTableDict_StdTableDictId",
                        column: x => x.StdTableDictId,
                        principalTable: "MainStdTableDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainStdTableColumnDict_StdTableDictId",
                table: "MainStdTableColumnDict",
                column: "StdTableDictId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainStdTableColumnDict");

            migrationBuilder.DropColumn(
                name: "TableTemplateType",
                table: "MainStdTableDict");

            migrationBuilder.RenameColumn(
                name: "Exp",
                table: "MainStdTableDict",
                newName: "Descr");

            migrationBuilder.AddColumn<string>(
                name: "StdTableCode",
                table: "MainStdTableDict",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.CreateTable(
                name: "MainStdTableColumnConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    StConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    Field = table.Column<string>(type: "text", nullable: false),
                    HeaderName = table.Column<string>(type: "text", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    Type = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdTableColumnConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdTableColumnConfig_MainStdTableDict_StConfigId",
                        column: x => x.StConfigId,
                        principalTable: "MainStdTableDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainStdTableColumnConfig_StConfigId",
                table: "MainStdTableColumnConfig",
                column: "StConfigId");
        }
    }
}
